<template>
  <div>
    <el-dialog
      :title="title"
      :visible.sync="show"
      :before-close="editCancel"
      width="40%"
    >
      <div class="formBox">
        <div class="formHead">{{ myTitle }}</div>
        <div class="formWhite">
          <div class="left">监测公司</div>
          <div class="right">
            <el-select
              v-model="itemForm.monitorId"
              size="small"
              placeholder="请选择"
              :disabled="detailDis"
            >
              <el-option
                v-for="item in jcCompanyList"
                :key="item.monitorId"
                :label="item.monitorName"
                :value="item.monitorId"
              ></el-option>
            </el-select>
          </div>
        </div>
        <div class="formGray">
          <div class="left">白蚁防治公司</div>
          <div class="right">
            <el-input
              v-model="itemForm.controlName"
              placeholder="请输入"
              size="small"
              :disabled="detailDis || myTitle == '编辑'"
            ></el-input>
          </div>
        </div>
        <div class="formWhite">
          <div class="left">账号</div>
          <div class="right">
            <el-input
              v-model="itemForm.accountNumber"
              placeholder="请输入"
              size="small"
              :disabled="detailDis"
            ></el-input>
          </div>
        </div>
        <div class="formGray">
          <div class="left">设备数量</div>
          <div class="right">
            <el-input
              v-model="itemForm.devicesNumber"
              placeholder="请输入"
              size="small"
              :disabled="true"
            ></el-input>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="editSure"
          size="small"
          v-if="myTitle == '编辑'"
          >确定</el-button
        >
        <el-button type="primary" plain @click="editCancel" size="small"
          >取消</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  updateMonitorCompany, // 绑定监测公司数据-编辑
  queryMonitorCompanyData, // 监测公司查询
} from "@/api/manage/asset";
import { string } from "tls";
export default {
  name: "detail",
  props: {
    show: {
      type: Boolean,
      default: false,
    },
    myTitle: {
      type: string,
      default: "",
    },
    detailDis: {
      type: Boolean,
      default: false,
    },
    itemForm: {},
  },
  data() {
    return {
      //   itemForm: {
      //     monitorId: "",
      //     monitorName: "",
      //     controlName: "",
      //     accountNumber: "",
      //     equipmentNum: "",
      //     id: ""
      //   },
      jcCompanyList: [],
    };
  },
  computed: {
    title() {
      return "监测公司绑定→" + this.myTitle;
    },
  },
  created() {
    queryMonitorCompanyData().then((res) => {
      if (res.errorCode == "000000") {
        this.jcCompanyList = res.data;
      }
    });
  },
  methods: {
    editSure() {
      console.log("提交", this.itemForm);
      let data = {
        accountNumber: this.itemForm.accountNumber,
        accountPassword: this.itemForm.accountPassword,
        controlId: this.itemForm.controlId,
        controlName: this.itemForm.controlName,
        devicesNumber: this.itemForm.devicesNumber,
        id: this.itemForm.id,
        monitorId: this.itemForm.monitorId,
        monitorName: this.itemForm.monitorName,
      };
      updateMonitorCompany(data).then((res) => {
        if (res.errorCode == "000000") {
          this.$modal.msgSuccess("编辑成功！");
          this.$emit("closeMsg", true);
        }
      });
    },
    editCancel() {
      this.$emit("closeMsg");
    },
    changeItem(val) {
      console.log(val, "0000");
      this.submitForm.monitorName = this.jcCompanyList.find(
        (item) => item.monitorId === val,
      ).monitorName;
    },
  },
};
</script>
<style lang="scss" scoped>
.headerTable {
  background: #5d6d7f;
  height: 48px;
  line-height: 48px;
  text-align: center;
  width: 100%;
  color: #fff;
  font-weight: Bold;
  font-size: 14px;
  font-family:
    Helvetica Neue,
    Helvetica,
    PingFang SC,
    Hiragino Sans GB,
    Microsoft YaHei,
    Arial,
    sans-serif;
  border: 1px solid #e3e3e3;
  border-bottom: 0;
}

.formBox {
  .left {
    display: inline-block;
    height: 44px;
    line-height: 44px;
    width: 140px;
    padding-right: 15px;
    border-left: 1px solid #e4e4dc;
    border-right: 1px solid #e4e4dc;
    font-family: MicrosoftYaHei;
    font-size: 12px;
    color: #303133;
    text-align: right;
    vertical-align: top;
  }
  .right {
    display: inline-block;
    width: calc(100% - 140px);
    height: 44px;
    border-right: 1px solid #e4e4dc;
    padding: 6px 15px;
    .el-select {
      width: 100% !important;
    }
    .el-input {
      width: 100% !important;
    }
  }
  .formHead {
    width: 100%;
    height: 44px;
    background-color: #73879c;
    height: 44px;
    line-height: 44px;
    text-align: center;
    font-family: MicrosoftYaHei, MicrosoftYaHei;
    font-weight: bold;
    font-size: 12px;
    color: #ffffff;
  }
  .formWhite {
    width: 100%;
    height: 44px;
    background-color: #fff;
    border-bottom: 1px solid #e4e4dc;
  }
  .area {
    .areaLeft {
      width: 40% !important;
      margin-right: 10px;
    }
    .areaRight {
      width: calc(60% - 10px) !important;
    }
  }
  .formGray {
    width: 100%;
    height: 44px;
    background-color: #eef0f2;
    border-bottom: 1px solid #e4e4dc;
  }
}
.red {
  color: red;
  margin-right: 2px;
  vertical-align: top;
}
::v-deep .el-dialog__header {
  border-bottom: 1px solid #e9e9ec;
}
::v-deep .el-dialog__footer {
  border-top: 1px solid #e9e9ec;
}
</style>
